package com.sunwayhorizo.health.hl7.rim;

import java.io.Serializable;
import java.sql.Timestamp;

import javax.persistence.Column;
import javax.persistence.DiscriminatorValue;
import javax.persistence.Entity;
import javax.persistence.Inheritance;
import javax.persistence.InheritanceType;
import javax.persistence.NamedQuery;

import org.jboss.seam.annotations.Name;

import com.sunwayhorizo.health.common.DataTypeUtil;
import com.sunwayhorizo.health.hl7.common.Hl7Exception;
import com.sunwayhorizo.health.hl7.datatypes.ANY;
import com.sunwayhorizo.health.hl7.datatypes.CE;
import com.sunwayhorizo.health.hl7.datatypes.SET_CE;
import com.sunwayhorizo.health.hl7.factories.ReferenceModifier;
import com.sunwayhorizo.health.hl7.persistent.RimCoreActCdSets;
import com.sunwayhorizo.health.hl7.vocabulary.ActCdSetCode;

import static com.sunwayhorizo.health.hl7.vocabulary.ActCdSetCode.*;

@Name("Observation")
@Entity
@Inheritance(strategy = InheritanceType.SINGLE_TABLE)
@DiscriminatorValue("OBS")
public class Observation extends Act implements Serializable
{

    /*
     * public SET_CE InterpretationCode; public SET_CE MethodCode; public SET_CE
     * TargetSiteCode; public ANY Value;
     */

    /**
     * 
     */
    private static final long serialVersionUID = 1L;


    public Observation() throws Hl7Exception
    {
    }


    public Observation(ReferenceModifier referencemodifier)
    {
        super(referencemodifier);
    }


    public void setMedicalHistory(CE medicalHistory)
    {
        setRimCoreActCdSets(medicalHistory, ActCdSetCode.MEDICALHISTORYCODE);
    }

    //得到会诊目的
    public CE getPurposeCode()
    {
        return DataTypeUtil.getCE(getRimCoreActCdSets(PURPOSECODE));
    }
    
    public void setPurposeCode(CE purposeCode)
    {
        setRimCoreActCdSets(purposeCode, ActCdSetCode.PURPOSECODE);
    }
    
    //得到会诊材料
    public CE getMedicalData(CE medicalData)
    {
        return DataTypeUtil.getCE(getRimCoreActCdSets(ActCdSetCode.MEDICALDATA));
    }
    
    public void setMedicalData(CE medicalData)
    {
        setRimCoreActCdSets(medicalData, ActCdSetCode.MEDICALDATA);
    }
    
    //得到病史
    public CE getMedicalHistory()
    {
        return DataTypeUtil.getCE(getRimCoreActCdSets(MEDICALHISTORYCODE));
    }
    
    public void setPhysicalSign(CE physicalSign)
    {
        setRimCoreActCdSets(physicalSign, ActCdSetCode.PHYSICALSIGN);
    }

    //得到体征
    public CE getPhysicalSign()
    {
        return DataTypeUtil.getCE(getRimCoreActCdSets(PHYSICALSIGN));
    }


    public void setInterpretationCode(CE interpretationCode)
    {
        if (null != interpretationCode && interpretationCode.codeSystemEnName() != null && interpretationCode.codeName() != null)
        {
            setRimCoreActCdSets(interpretationCode, OBINTERPRETATIONCDSETCODE);
        }
        else
        {
            this.setObInterpretationCodeEtsId(interpretationCode.code().toString());
        }
    }


    /**
     * 得到诊断
     * 
     * @return CE
     * @throws Hl7Exception
     */
    public CE getInterpretationCode() throws Hl7Exception
    {
        if (this.getObInterpretationCodeEtsId().equals(OBINTERPRETATIONCDSETCODE.toString()))
        {
            for (RimCoreActCdSets actCdSets : this.getActCdSetsList())
            {
                if (this.getObInterpretationCodeEtsId().equals(actCdSets.getAttributeTypeCode()))
                {
                    return DataTypeUtil.getCE(actCdSets);
                }
            }
        }
        else
            return DataTypeUtil.getCE(this.getObInterpretationCodeEtsId());
        return null;
    }


    public void setMethodCode(CE methodCode)
    {
        if (null != methodCode && methodCode.codeSystemEnName() != null && methodCode.codeName() != null)
        {
            setRimCoreActCdSets(methodCode, OBMETHODCDSETCODE);
        }
        else
        {
            this.setObMethodCodeEtsId(methodCode.code().toString());
        }
    }


    /**
     * 得到诊断类型字典
     * 
     * @return CE
     * @throws Hl7Exception
     */
    public CE getMethodCode() throws Hl7Exception
    {
        if (this.getObMethodCodeEtsId().equals(OBMETHODCDSETCODE.toString()))
        {
            for (RimCoreActCdSets actCdSets : this.getActCdSetsList())
            {
                if (this.getObMethodCodeEtsId().equals(actCdSets.getAttributeTypeCode()))
                {
                    return DataTypeUtil.getCE(actCdSets);
                }
            }
        }
        else
            return DataTypeUtil.getCE(this.getObMethodCodeEtsId());
        return null;
    }


    public void setTargetSiteCode(CE targetSiteCode)
    {
        if (null != targetSiteCode && targetSiteCode.codeSystemEnName() != null && targetSiteCode.codeName() != null)
        {
            setRimCoreActCdSets(targetSiteCode, OBTARGETSITECDSETCODE);
        }
        else
        {
            this.setObTargetsiteCodeEtsId(targetSiteCode.code().toString());
        }
    }


    public CE getTargetSiteCode() throws Hl7Exception
    {
        if (this.getObTargetsiteCodeEtsId().equals(OBTARGETSITECDSETCODE.toString()))
        {
            for (RimCoreActCdSets actCdSets : this.getActCdSetsList())
            {
                if (this.getObTargetsiteCodeEtsId().equals(actCdSets.getAttributeTypeCode()))
                {
                    return DataTypeUtil.getCE(actCdSets);
                }
            }
        }
        else
            return DataTypeUtil.getCE(this.getObTargetsiteCodeEtsId());
        return null;
    }


    public void setValue(ANY Value)
    {
        this.setObValueTxt(Value.toString());
    }


    public ANY getValue() throws Hl7Exception
    {
        ANY any = DataTypeUtil.getCS(this.getObValueTxt());
        return any;
    }

    // Observation
    @Column(name = "OB_DENOM_VALUE_TXT")
    private String obDenomValueTxt;
    @Column(name = "OB_DENOM_VALUE_UOM_CODE")
    private String obDenomValueUomCode;
    @Column(name = "OB_HIGH_VALUE_INCLUSIVE_FLAG")
    private String obHighValueInclusiveFlag;
    @Column(name = "OB_HIGH_VALUE_TXT")
    private String obHighValueTxt;
    @Column(name = "OB_HIGH_VALUE_UOM_CODE")
    private String obHighValueUomCode;
    @Column(name = "OB_IVL_VALUE_TXT")
    private String obIvlValueTxt;
    @Column(name = "OB_IVL_VALUE_UOM_CODE")
    private String obIvlValueUomCode;
    @Column(name = "OB_LOW_VALUE_INCLUSIVE_FLAG")
    private String obLowValueInclusiveFlag;
    @Column(name = "OB_LOW_VALUE_TXT")
    private String obLowValueTxt;
    @Column(name = "OB_LOW_VALUE_UOM_CODE")
    private String obLowValueUomCode;
    @Column(name = "OB_NUMER_VALUE_TXT")
    private String obNumerValueTxt;
    @Column(name = "OB_NUMER_VALUE_UOM_CODE")
    private String obNumerValueUomCode;
    @Column(name = "OB_VALUE_CODE_ETS_ID")
    private String obValueCodeEtsId;
    @Column(name = "OB_VALUE_DATE_TS")
    private Timestamp obValueDateTs;
    @Column(name = "OB_VALUE_DATE_TXT")
    private String obValueDateTxt;
    @Column(name = "OB_VALUE_FLAG")
    private String obValueFlag;
    @Column(name = "OB_VALUE_NUM")
    private Long obValueNum;
    @Column(name = "OB_VALUE_ST_TXT")
    private String obValueStTxt;
    @Column(name = "OB_VALUE_TXT")
    private String obValueTxt;
    @Column(name = "OB_VALUE_TYPE_CODE")
    private String obValueTypeCode;
    @Column(name = "OB_VALUE_UOM_CODE")
    private String obValueUomCode;

    @Column(name = "OB_INTERPRETATION_CODE_ETS_ID")
    private String obInterpretationCodeEtsId = OBINTERPRETATIONCDSETCODE.toString();
    @Column(name = "OB_METHOD_CODE_ETS_ID")
    private String obMethodCodeEtsId = OBMETHODCDSETCODE.toString();
    @Column(name = "OB_TARGETSITE_CODE_ETS_ID")
    private String obTargetsiteCodeEtsId = OBTARGETSITECDSETCODE.toString();


    private String getObInterpretationCodeEtsId()
    {
        return obInterpretationCodeEtsId;
    }


    private void setObInterpretationCodeEtsId(String obInterpretationCodeEtsId)
    {
        this.obInterpretationCodeEtsId = obInterpretationCodeEtsId;
    }


    private String getObMethodCodeEtsId()
    {
        return obMethodCodeEtsId;
    }


    private void setObMethodCodeEtsId(String obMethodCodeEtsId)
    {
        this.obMethodCodeEtsId = obMethodCodeEtsId;
    }


    private String getObTargetsiteCodeEtsId()
    {
        return obTargetsiteCodeEtsId;
    }


    private void setObTargetsiteCodeEtsId(String obTargetsiteCodeEtsId)
    {
        this.obTargetsiteCodeEtsId = obTargetsiteCodeEtsId;
    }


    protected String getObDenomValueTxt()
    {
        return obDenomValueTxt;
    }


    protected void setObDenomValueTxt(String obDenomValueTxt)
    {
        this.obDenomValueTxt = obDenomValueTxt;
    }


    protected String getObDenomValueUomCode()
    {
        return obDenomValueUomCode;
    }


    protected void setObDenomValueUomCode(String obDenomValueUomCode)
    {
        this.obDenomValueUomCode = obDenomValueUomCode;
    }


    protected String getObHighValueInclusiveFlag()
    {
        return obHighValueInclusiveFlag;
    }


    protected void setObHighValueInclusiveFlag(String obHighValueInclusiveFlag)
    {
        this.obHighValueInclusiveFlag = obHighValueInclusiveFlag;
    }


    protected String getObHighValueTxt()
    {
        return obHighValueTxt;
    }


    protected void setObHighValueTxt(String obHighValueTxt)
    {
        this.obHighValueTxt = obHighValueTxt;
    }


    protected String getObHighValueUomCode()
    {
        return obHighValueUomCode;
    }


    protected void setObHighValueUomCode(String obHighValueUomCode)
    {
        this.obHighValueUomCode = obHighValueUomCode;
    }


    protected String getObIvlValueTxt()
    {
        return obIvlValueTxt;
    }


    protected void setObIvlValueTxt(String obIvlValueTxt)
    {
        this.obIvlValueTxt = obIvlValueTxt;
    }


    protected String getObIvlValueUomCode()
    {
        return obIvlValueUomCode;
    }


    protected void setObIvlValueUomCode(String obIvlValueUomCode)
    {
        this.obIvlValueUomCode = obIvlValueUomCode;
    }


    protected String getObLowValueInclusiveFlag()
    {
        return obLowValueInclusiveFlag;
    }


    protected void setObLowValueInclusiveFlag(String obLowValueInclusiveFlag)
    {
        this.obLowValueInclusiveFlag = obLowValueInclusiveFlag;
    }


    protected String getObLowValueTxt()
    {
        return obLowValueTxt;
    }


    protected void setObLowValueTxt(String obLowValueTxt)
    {
        this.obLowValueTxt = obLowValueTxt;
    }


    protected String getObLowValueUomCode()
    {
        return obLowValueUomCode;
    }


    protected void setObLowValueUomCode(String obLowValueUomCode)
    {
        this.obLowValueUomCode = obLowValueUomCode;
    }


    protected String getObNumerValueTxt()
    {
        return obNumerValueTxt;
    }


    protected void setObNumerValueTxt(String obNumerValueTxt)
    {
        this.obNumerValueTxt = obNumerValueTxt;
    }


    protected String getObNumerValueUomCode()
    {
        return obNumerValueUomCode;
    }


    protected void setObNumerValueUomCode(String obNumerValueUomCode)
    {
        this.obNumerValueUomCode = obNumerValueUomCode;
    }


    protected String getObValueCodeEtsId()
    {
        return obValueCodeEtsId;
    }


    protected void setObValueCodeEtsId(String obValueCodeEtsId)
    {
        this.obValueCodeEtsId = obValueCodeEtsId;
    }


    protected Timestamp getObValueDateTs()
    {
        return obValueDateTs;
    }


    protected void setObValueDateTs(Timestamp obValueDateTs)
    {
        this.obValueDateTs = obValueDateTs;
    }


    protected String getObValueDateTxt()
    {
        return obValueDateTxt;
    }


    protected void setObValueDateTxt(String obValueDateTxt)
    {
        this.obValueDateTxt = obValueDateTxt;
    }


    protected String getObValueFlag()
    {
        return obValueFlag;
    }


    protected void setObValueFlag(String obValueFlag)
    {
        this.obValueFlag = obValueFlag;
    }


    protected Long getObValueNum()
    {
        return obValueNum;
    }


    protected void setObValueNum(Long obValueNum)
    {
        this.obValueNum = obValueNum;
    }


    protected String getObValueStTxt()
    {
        return obValueStTxt;
    }


    protected void setObValueStTxt(String obValueStTxt)
    {
        this.obValueStTxt = obValueStTxt;
    }


    protected String getObValueTxt()
    {
        return obValueTxt;
    }


    protected void setObValueTxt(String obValueTxt)
    {
        this.obValueTxt = obValueTxt;
    }


    protected String getObValueTypeCode()
    {
        return obValueTypeCode;
    }


    protected void setObValueTypeCode(String obValueTypeCode)
    {
        this.obValueTypeCode = obValueTypeCode;
    }


    protected String getObValueUomCode()
    {
        return obValueUomCode;
    }


    protected void setObValueUomCode(String obValueUomCode)
    {
        this.obValueUomCode = obValueUomCode;
    }

}
